package Servlet.StudentServlet;

import Entity.Student;
import Service.StudentService.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
/*
负责学生 登陆 数据接口
 */
@WebServlet(value = "/studentLogin")
public class StudentLogin extends HttpServlet {
    private StudentService studentService = new StudentService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        String studentId =  request.getParameter("studentId");
        String studentPassword = request.getParameter("studentPassword");


        Student student = new Student(studentId,studentPassword);

        student = studentService.studentLogin(student);


        PrintWriter out = response.getWriter();
        if (student==null){
            out.print(0);
        }else{

            HttpSession session = request.getSession();
            session.setAttribute("student",student);
            out.print(1);
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
